package com.jdrx.sw.sewage.api.open;

import com.jdrx.platform.commons.rest.beans.dto.IdDTO;
import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.LogoSetDTO;
import com.jdrx.sw.sewage.beans.vo.LogoSetVO;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.LogoSetServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "/api/logoSet")
@Api(value = "logo设置")
public class LogoSetApi {

    @Autowired
    private LogoSetServiceImpl logoSetServiceImpl;

    @ApiOperation(value = "查询logo")
    @RequestMapping(value = "find", method = RequestMethod.POST)
    public ResponseVO<LogoSetVO> findMaintenanceDevList() {
        return ResponseFactory2.ok(logoSetServiceImpl.findLogo());
    }

    @ApiOperation(value = "新增logo")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public ResponseVO add(@RequestHeader(Constant.DATA_NODE) String dataNode,
                          @RequestHeader(Constant.TENANT_ID) String tenantId,
                          @RequestBody @Valid LogoSetDTO logoSetDTO) throws BizException {
        return logoSetServiceImpl.add(logoSetDTO);
    }

    @ApiOperation(value = "更新logo")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public ResponseVO update(@RequestHeader(Constant.DATA_NODE) String dataNode,
                             @RequestHeader(Constant.TENANT_ID) String tenantId,
                             @RequestBody @Valid LogoSetDTO logoSetDTO) throws BizException {
        logoSetServiceImpl.update(logoSetDTO);
        return ResponseFactory2.ok();
    }

    @ApiOperation(value = "恢复默认logo")
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public ResponseVO delete(@RequestHeader(Constant.DATA_NODE) String dataNode,
                             @RequestHeader(Constant.TENANT_ID) String tenantId,
                             @RequestBody @Valid IdDTO dto) throws BizException {
        logoSetServiceImpl.delete(dto);
        return ResponseFactory2.ok();
    }
}
